package com.vonchange.water.pvm.behavior;

import com.vonchange.water.pvm.RunUtil;
import com.vonchange.water.pvm.exception.EnumErrorCode;
import com.vonchange.water.pvm.exception.ProcessEngineException;
import com.vonchange.water.pvm.execution.ActivityExecution;
import com.vonchange.water.pvm.model.definition.PvmActivity;
import com.vonchange.water.pvm.model.definition.PvmLine;

public class LineActivityBehavior extends AbstractActivityBehavior{
    @Override
    public void executeMain(ActivityExecution execution) throws Exception {
        //, PvmActivity current
        PvmLine pvmLine = (PvmLine) execution.getCurrentActivity();
        PvmActivity pvmActivity = (PvmActivity) execution.findPvmActivity(pvmLine.getToId());
        ActivityBehavior activityBehavior= RunUtil.findActivityBehaviorByType(pvmActivity.getActivityConfig().getType());
        if(null==activityBehavior){
            throw new ProcessEngineException(EnumErrorCode.ActivityBehaviorNull);
        }
        ActivityExecution executionTo = new ActivityExecution();
        executionTo.setCurrentActivityId(pvmActivity.getId());
        executionTo.setProcessInstance(execution.getProcessInstance());
        activityBehavior.execute(executionTo);
    }

    @Override
    public String activityType() {
        return "line";
    }

}
